<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <title>AllUSer</title>
    <script src="<%=basePath%>/js/jquery.js"></script>
    <script src="<%=basePath%>/js/util/util.js"></script>
    <script>
        function delUser(id) {
            $.ajax({
                type:"POST",
                url : "<%=basePath%>user/delUser.do",
                data : {
                    id : id
                },
                success : function(meg) {
                    alert("删除成功");
                    window.location="<%=basePath%>user/getAllUser.do";
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("网络错误");
                }
            });
        }
        function addUser(){
            window.location="<%=basePath%>user/toAddAndUpUser.do?type=add";
        }
     </script>
</head>
<body>
<button onclick="addUser()">增加</button>
<table  >
    <thead>
    <tr>
        <th width="5%">序号</th>
        <th width="5%">姓名</th>
        <th width="5%">id</th>
        <th width="15%">密码</th>
        <th width="15%">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${users}" var="l" varStatus="s">
        <tr>
            <td>${s.index+1}</td>
            <td>${l.userName}</td>
            <td>${l.id}</td>
            <td>${l.password}</td>
            <td>${l.age}</td>
            <td>${l.gender}</td>
            <td><a href="<%=basePath%>user/toAddAndUpUser.do?id=${l.id}">修改</a></td>
            <td><a href="javascript:delUser(${l.id});">删除</a></td>
        </tr>
    </c:forEach>
    </tbody>
</table>

</body>
</html>
